// pages/map/add/add.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		region: ['请选择', '', ''],
		isChecked: false,
		iphone: '',
		name: '',
		city: '',
		tim:''
	},
	onLoad(e){
		wx.request({
			url:getApp().globalData.http+'action=showAddress&ID='+e.id,
			success: (res) => {
				console.log(res)
				this.setData({
					id:e.id,
					tim:res.data.data,
					region:[res.data.data.Prov,res.data.data.City,res.data.data.County],
					sta:2,
					name:res.data.data.REALNAME,
					iphone:res.data.data.MOBILE,
					city:res.data.data.ADDRESS
				})
				
			}
		})
	},
	name1(e) {
		this.setData({
			name: e.detail.value
		})
	},
	city1(e) {
		this.setData({
			city: e.detail.value
		})
	},
	iphone1(e) {
		this.setData({
			iphone: e.detail.value
		})
	},
	bindRegionChange: function(e) {
		this.setData({
			region: e.detail.value
		})
	},
	changeSwitch(e) {
		console.log(e.detail.value)
		this.setData({
			isChecked: e.detail.value
		})
	},
	sure() {
		if(this.data.name!=''&& this.data.iphone!=''&& this.data.city!=''&&this.data.region[0]!='请选择'){
		wx.getStorage({
			key: 'uid',
			success: (e) => {
				wx.request({
					url: getApp().globalData.http + 'action=updateAddress&uname='
					+this.data.name + '&mobile=' + this.data.iphone + '&uid=' + e.data.uid +
					'&prov=' + this.data.region[0] + '&city=' + this.data.region[1] +
					'&county=' + this.data.region[2] + '&address=' + this.data.city + '&isDefault=' + this.data.isChecked
					+'&ID='+this.data.id,
					success: (res) => {
						console.log(res)
						wx.navigateBack({
							delta:1
						})
					}
				})
			}
		})
}else{
			wx.showToast({
				title:'请正确填写资料',
				icon:'none'
			})
		}
	}
})
